<template>
  <!-- 评分标准 -->
  <div>
    <table-box
      ref="scoringCriteria"
      :selected-arry.sync="tableSelected"
      :table-config="tableConfig"
      :other-filters="otherFilters"
      :off-set="-20"
      show-index
      @btnOperate="btnOperate"
    />
    <add-scoring-criteria v-if="showEdit" ref="ScoreCriteriaDlg" :visible.sync="showEdit" :detail-data="activatedData" @success="refreshTable" />
  </div>
</template>

<script>
import addScoringCriteria from './component/addScoringCriteria.vue'
export default {
  name: 'ScoringCriteria',
  components: { addScoringCriteria },
  data() {
    return {
      showEdit: false,
      activatedData: {},
      tableSelected: [],
      otherFilters: [],
      tableConfig: {
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/configScoreCriteria/page`,
        hideSearchBar: true,
        setting: [
          {
            prop: 'scoreNature',
            label: '考核性质',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'SCORE_NATURE'
            }
          },
          {
            prop: 'scoreType',
            label: '考核类别',
            className: 'table-handelclick-text',
            isButton: true,
            clickFun: this.checkDetail
          },
          {
            prop: 'totalScore',
            label: '总分值'
          },
          {
            prop: 'scoreDesc',
            label: '考核说明'
          }
        ],
        btnList: this.isProduction ? null : [
          {
            buttonName: '新增',
            optCode: 'add',
            outerFlag: true
          },
          {
            buttonName: '编辑',
            optCode: 'edit',
            outerFlag: true
          }
        ]
      }
    }
  },
  created() {},
  activated() {},
  methods: {// 按钮组
    btnOperate(flag) {
      switch (flag) {
        case 'add':
          this.handleEdit()
          break
        case 'edit':
          if (!this.singleJudge(this.tableSelected, '编辑', false)) {
            return
          }
          this.handleEdit(this.tableSelected[0])
          // this.handleEdit('edit')
          break
      }
    },
    // 新增/编辑
    handleEdit(data) {
      this.activatedData = {}
      if (data) {
        this.activatedData.data = data
        this.activatedData.flag = 'edit'
      }
      this.showEdit = true
    },
    checkDetail(data) {
      this.activatedData.data = data
      this.activatedData.flag = 'detail'
      this.showEdit = true
    },
    // 刷新
    refreshTable(isInit) {
      this.$refs.scoringCriteria.initTableData(isInit ? '' : 'onPage')
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/.table-handelclick-text {
  color: #3DC094;
  cursor: pointer;
}
</style>
